/*//////////////////////////////////////////////////////////////////////////////
//
//                  INTEL CORPORATION PROPRIETARY INFORMATION
//     This software is supplied under the terms of a license agreement or
//     nondisclosure agreement with Intel Corporation and may not be copied
//     or disclosed except in accordance with the terms of that agreement.
//          Copyright(c) 2005-2008 Intel Corporation. All Rights Reserved.
//
*/

#ifndef __SBR_DEC_API_INT_H__
#define __SBR_DEC_API_INT_H__

/********************************************************************/

#include "ippac.h"
#include "ipps.h"
#include "sbr_dec_struct.h"
#include "sbr_dec_settings_int.h"
#include "aaccmn_chmap.h"
#include "aac_dec_int.h"
#include "align.h"

/********************************************************************/

typedef struct { // specification Filter

  Ipp8u*              pMemSpecQMFA[2];
  Ipp8u*              pMemSpecQMFS[2];

} sSbrDecFilter;

/********************************************************************/

typedef struct { //  sbr matrix's work space

/* main-matrix
 *
 * UMC name | ISO name
 *  Xbuf    |   Xlow
 *  YBuf    |   Xhigh & Y - identity
 *  Zbuf    |     X
 *
 * Please, to watch closely
 */
  Ipp32s*  iXBuf[2][40];

  Ipp32s*  iYBuf[2][40];

  /*
   * Zbuf - will be used by vector's state
  */

  /* these descriptors contain pointer to the allocatable memory (main matrix).
  /  It is need, because mixing wiil be done
  */
  Ipp32s* _dcMemoryMatrix[2];

/* HF adjustment: these buffers keep Noise & Gain data */

  Ipp32s  iBufGain[2][MAX_NUM_ENV][MAX_NUM_ENV_VAL];
  Ipp32s  iBufNoise[2][MAX_NUM_ENV][MAX_NUM_ENV_VAL];

  Ipp32s  bufEnvOrig[2][5*64];
  Ipp32s  sfsEOrig[2][5];
  Ipp32s  bufNoiseOrig[2][2*5];

  /* for HF generation */
  Ipp32s  bwArray[2][MAX_NUM_NOISE_VAL];

/* external buffer for delay of A, S & SD FILTERs */
  Ipp32s  AnalysisBufDelay[2][320];
  Ipp32s  SynthesisBufDelay[2][1280];
  Ipp32s  SynthesisDownBufDelay[2][1280];

} sSBRDecWorkState;

/********************************************************************/

typedef struct {
  sSBRDecComState    comState;
  sSBRDecWorkState   wsState;

} sSBRBlock;

/********************************************************************/

#ifdef  __cplusplus
extern  "C" {
#endif

 /* algorithm */

  Ipp32s sbriDequantization(sSBRDecComState* pSbrCom, sSBRDecWorkState* pSbrWS,
                            Ipp32s* sfsEnv, Ipp32s ch, Ipp32s bs_amp_res);

  Ipp32s sbriGenerationHF(Ipp32s** iXBuf,
                          Ipp32s** iYBuf,
                          sSBRDecComState* comState, Ipp32s* bwArray, Ipp32s* degPatched,
                          Ipp32s ch, Ipp32s decode_mode);

  void sbriAdjustmentHF(Ipp32s**  iYBuf,
                        Ipp32s* bufEnvOrig, Ipp32s* bufNoiseOrig,
                        Ipp32s* sfsEOrig,
                        Ipp32s iBufGain[][MAX_NUM_ENV_VAL],Ipp32s iBufNoise[][MAX_NUM_ENV_VAL],
                        sSBRDecComState* comState, Ipp32s *degPatched, Ipp8u *WorkBuffer,
                        Ipp32s reset, Ipp32s ch, Ipp32s decode_mode);

  Ipp32s sbriSynthesisFilter_32s(Ipp32s* bufZRe,
                                 Ipp32s* pDst,
                                 Ipp8u* pSpec,
                                 Ipp32s* scaleFactor,
                                 Ipp32s mode);


/* SBR GENERAL HIGH LEVEL API: FIXED POINT VERSION */
 // init()
  Ipp32s sbridecInitFilter(AACDec *pState);
  void sbridecDrawMemMap(sSbrDecFilter** pDC, Ipp8u* pMem, Ipp32s* pSizes);
  void sbridecUpdateMemMap(sSbrDecFilter** pDC, Ipp32s mShift);

  /* internal buffer size is MAX (HQ mode, LP mode) */
  Ipp32s sbridecGetFilterSize(Ipp32s* pFilterSize);
  void sbriInitDecoder(sSBRBlock* pState[CH_MAX], void* pMem);
  void sbriDecoderGetSize(Ipp32s *pSize);

 // reset()
  Ipp32s sbridecReset(sSBRBlock* pSbr);

 // get_frame()
  Ipp32s sbriGetFrame(Ipp32s *pSrc, Ipp32s *pDst,
                      sSBRBlock * pSbr, sSbrDecFilter* sbr_filter,
                      Ipp32s ch, Ipp32s decode_mode,
                      Ipp32s dwnsmpl_mode, Ipp8u* pWorkBuffer, Ipp32s* scaleFactor);

 // free()
  Ipp32s sbridecFreeFilter(sSbrDecFilter* pDC[CH_MAX]);
  Ipp32s sbriFreeDecoder(sSBRBlock * pDst);
/* end */

#ifdef  __cplusplus
}
#endif

/********************************************************************/

#endif             /* __SBR_DEC_API_INT_H__ */
